﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using GroundWater.Data;
using GroundWater.BusinessActions;
using WellTable = GroundWater.Data.InfoDataSet.WellsDataTable;
using WellRow = GroundWater.Data.InfoDataSet.WellsRow;

namespace GroundWater.Basedata
{
    public partial class WellView : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                string id = Request.QueryString["id"];
                if (!String.IsNullOrEmpty(id))
                {
                    SetFields(id);

                    //aWaterlevel.Visible = true;
                    //aSpline.Visible = true;
                    //aColumn.Visible = true;

                    //aColumn.NavigateUrl = "../waterlevel/waterlevelchart.aspx?id=" + id;
                    //aSpline.NavigateUrl = "../waterlevel/WaterLevelByDate.aspx?id=" + id;
                    //aWaterlevel.NavigateUrl = "../waterlevel/monitoringquery.aspx?id=" + id;
                }
                else
                {
                    //aWaterlevel.Visible = false;
                    //aSpline.Visible = false;
                    //aColumn.Visible = false;
                }
            }

        }

        private void SetFields(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                WellRow row = Well.GetById(id, false);
                if (!row.IsBTUAddressNull())
                {
                    txtBTUAddress.Text = row.BTUAddress;
                }

                if (!row.IsDepthNull())
                {
                    txtDepth.Text = row.Depth.ToString();
                }
                if (!row.IsLongitudeNull())
                {
                    txtLongitude.Text = row.Longitude.ToString();
                }
                if (!row.IsLatitudeNull())
                {
                    txtLatitude.Text = row.Latitude.ToString();
                }

                if (!row.IsSectionPlaneNull())
                {
                    txtSectionPlane.Text = row.SectionPlane;
                }
                if (!row.IsShaftSinkingDateNull())
                {
                    txtShaftSinkingDate.Text = row.ShaftSinkingDate.ToString("yyyy-MM-dd");
                }

                if (!row.IsBTUAddressNull())
                {
                    txtSIMCard.Text = row.SIMCard;
                }
                txtWellCode.Text = row.Code;
                txtWellName.Text = row.Name;
                txtAdministrativeDivisionsCode.Text = row.AdministrativeDivisionsCode;
                txtDesignYearlyWaterQuantity.Text = row.DesignYearlyWaterQuantity.ToString();
                txtFunctionRegionCode.Text = row.FunctionRegionCode;
                txtResourceRegionCode.Text = row.ResourceRegionCode;
                txtWaterSource.Text = row.WaterSource;

                if (!row.IsAdministrationNull())
                {
                    txtAdministration.Text = row.Administration;
                }

                if (!row.IsDesignFlowRateNull())
                {
                    txtDesignFlowRate.Text = row.DesignFlowRate.ToString();
                }
                if (!row.IsDiameterNull())
                {
                    txtDiameter.Text = row.Diameter.ToString();
                }

                if (!row.IsDynamicLevelNull())
                {
                    txtDynamicLevel.Text = row.DynamicLevel.ToString();
                }

                if (!row.IsLandformNull())
                {
                    txtLandform.Text = row.Landform;
                }

                if (!row.IsProjectRuningStateNull())
                {
                    txtProjectRuningState.Text = row.ProjectRuningState;
                }
                if (!row.IsPumpTypeNull())
                {
                    txtPumpType.Text = row.PumpType;
                }

                if (!row.IsRemoveEquipmentNull())
                {
                    txtRemoveEquipment.Text = row.RemoveEquipment;
                }

                if (!row.IsStaticLevelNull())
                {
                    txtStaticLevel.Text = row.StaticLevel.ToString();
                }

                if (!row.IsWaterQualityNull())
                {
                    txtWaterQuality.Text = row.WaterQuality;
                }

                if (!row.IsAltitudeNull())
                {
                    txtAltitude.Text = row.Altitude.ToString();
                }

                if (!row.IsSequenceNumberNull())
                {
                    txtSequenceNumber.Text = row.SequenceNumber.ToString();
                }



                //this.ViewState["WellId"] = id;
                lblTitle.Text = row.Name;
            }
        }

    }
}
